<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with local network - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=local+network</link>
      <pubDate>Sun, 08 Aug 2021 18:47:09 +0000</pubDate>
         <description>Tagged with local network - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedlocal+network/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>communicate between two macs in processing</title>
      <link>https://forum.processing.org/two/discussion/25841/communicate-between-two-macs-in-processing</link>
      <pubDate>Fri, 05 Jan 2018 20:53:36 +0000</pubDate>
      <dc:creator>Faffie</dc:creator>
      <guid isPermaLink="false">25841@/two/discussions</guid>
      <description><![CDATA[<p>Hello world,
I would like to know if it is possible to communicate between two macs in processing. What I mean:</p>

<p><em>Mac1 sends a signal to mac2 -&gt; mac2 plays an audio file -&gt; mac 2 waits for another signal sent by mac1 (loop)</em></p>

<p>In the code I have written I would love to send a signal to the second mac (mac2) at "int S5_MUSIC = 5;". So that there will be two sounds played at the same time. I need the second mac for a second pair of boxes, to create a surround sound....</p>

<p><strong>This is my processing code:</strong></p>

<pre><code>import processing.serial.*;
import processing.sound.*;


int S1_WAITING_FOR_PEOPLE  = 1;
int S2_PEOPLE_ENTERED      = 2;
int S3_LIGHT_FADE_OUT      = 3;
int S4_DARK                = 4;
int S5_MUSIC               = 5;
int S6_LIGHT_FADE_IN       = 6;
// make sure this is the last!!!!
int TERMINATE              = 7;

int mode = S1_WAITING_FOR_PEOPLE;




int no_one_when_distance_greater_then = 160; // cm
int time_before_dim = 5000; // ms

SoundFile file;
boolean is_playing = false;

Serial myPort;  

int dist;

boolean someone_present = false;
int someone_present_since_time;


int music_playing_since;
int music_duration;

int in_mode_since_ms;

void setup() {
  size(640, 360);

  printArray(Serial.list()); // "/dev/cu.usbmodem1411" cu.usb!!!

  myPort = new Serial(this, Serial.list()[1], 9600);
  //myPort.readStringUntil('\n');
  myPort.bufferUntil('\n');

  // Load a soundfile from the data folder of the sketch and play it back in a loop
  file = new SoundFile(this, "Ex.wav");
  //file.loop();
  music_duration = (int) file.duration() * 1000;
  music_duration += 2000;

}      

void draw() {
  background(0);
  fill(255);
  text("frameCount: "+frameCount, 50, 25);
  text("dist: "+dist, 50, 50);
  text("mode: "+mode, 50, 75);


  if (frameCount == 180) {
    turn_on();
  } else if (frameCount &gt; 180) {

    if ( mode == S1_WAITING_FOR_PEOPLE) {

      if (someone_present == false) {
        if (dist &lt; no_one_when_distance_greater_then) {
          someone_present = true;
          someone_present_since_time = millis();
          change_mode(mode + 1);
        }
      }
    } else if (mode == S2_PEOPLE_ENTERED) {
      text("millis: "+millis(), 50, 100);
      text("someone_present_since_time: "+someone_present_since_time, 50, 125);
      text("time_before_dim: "+time_before_dim, 50, 150);
      if (millis() - someone_present_since_time &gt; time_before_dim) {
        change_mode(mode + 1);
      }
    } else if (mode == S3_LIGHT_FADE_OUT) {
      turn_off();
      change_mode(mode + 1);
    } else if (mode == S4_DARK) 
    {
      change_mode(mode + 1);
    } else if (mode == S5_MUSIC) 
    {
      if (is_playing == false) {
        file.play();
        is_playing = true;
        music_playing_since = millis();
      }
      if (millis() - music_playing_since &gt; music_duration) {
        is_playing = false;
        file.stop();
        change_mode(mode + 1);
      }
    } else if (mode == S6_LIGHT_FADE_IN) 
    {
      // todo
      if (millis() - in_mode_since_ms &gt; 1000) {
        change_mode(mode + 1);
      }

    } else if (mode == TERMINATE) 
    {
      change_mode(S1_WAITING_FOR_PEOPLE);
      someone_present = false; // reset
      println("turn_on();");
      turn_on();
    }
  }
}


void change_mode(int m) {
  mode = m;
  in_mode_since_ms = millis();
}



void serialEvent(Serial p) { 
  String s = p.readString();
  if (s != null) {
    s = s.replace("\r\n", "");
    if (s.contains("Distance Measured")) {
      String[] tokens = split(s, "=");
      dist = int(tokens[1]);
    }
  }
} 


void turn_on() {
  myPort.write("on");
}

void turn_off() {
  myPort.write("off");
}

void keyPressed() {
  if (key == 'a') {
    turn_on();
  }
  if (key == 's') {
    turn_off();
  }
}
</code></pre>

<p>Thanks for your effort.
Faffie</p>
]]></description>
   </item>
   <item>
      <title>Networked Cat - image upload and mailer not being triggered by serial events</title>
      <link>https://forum.processing.org/two/discussion/12828/networked-cat-image-upload-and-mailer-not-being-triggered-by-serial-events</link>
      <pubDate>Mon, 05 Oct 2015 04:22:21 +0000</pubDate>
      <dc:creator>patalanov</dc:creator>
      <guid isPermaLink="false">12828@/two/discussions</guid>
      <description><![CDATA[<p>I have a <strong>php server</strong> running <strong>127.0.0.1:8080</strong> on the root of this structure:</p>

<p>**NetworkedCat&gt;</p>

<pre><code>                   |data|&gt;script-cat.php

                   index.html

                   NetworkedCat.pde

                   img.jpg

                   save2web.php

                   |swiftmailer|**
</code></pre>

<p>this Arduino-based app should:</p>

<p><strong>1) receive an input from a pressure sensor;
2) verify whether threshold is surpassed
3) take picture from build-in camera
4) upload pic to website
5) mail me about the upload</strong></p>

<p>testing on browser, <strong>save2web.php</strong> and <strong>cat-script.php</strong> are working, 
that is, scripts are uploading and emailing.</p>

<p>pressure sensor is also reading and printing, and threshold have been calibrated.</p>

<p>but  <strong>NetworkedCat.pde</strong> is NOT triggering the events.</p>

<p>please note:</p>

<p><strong>Processing</strong> opens localhost at another port (80), 
because php server works on 8080.</p>

<p>are they compatible?</p>

<p>why is the Processing code below not woking?</p>

<p>if I shorten the Processing code, and test the image capture and upload only, it works.
so, the bug must be related to the serial events.</p>

<p>please help!</p>

<pre><code>/*Serial String reader
Context: Arduino

Reads in a string of characters until it gets a linefeed (ASCII 10).
then converts the string into a number
*/

import processing.serial.*;
import processing.video.*;
import processing.net.*;

Serial myPort;              //the serial port
float sensorValue = 0;      //the value form the sensor
float prevSensorValue = 0;  //previous value from the sensor
int threshold = 200;        //above this number, the cat is on the mat

int currentTime = 0;       //the current time as a single number
int lastMailTime = 0;      //last minute you sent a mail
int mailInterval = 60;     //minimum seconds betweeen mails
String mailUrl = "cat-script.php";
int lastPicture = 0;       //last minute you sent a picture
int lastPictureTime = 0;   //last minute you sent a picture
int pictureInterval = 10;  //minimum seconds between pictures

Capture myCam;            //camera capture library instance
String fileName = "img.jpg"; //file name for the picture

//location on your server for the picture script:
String pictureScriptUrl = "save2web.php";
String boundary = "----H4rkNrF"; //string boundary for the post request

Client thisClient;        //instance for the net library


//float xPos = 0;             //horizontal position of the graph
//float lastXPos = 0;         //previous horizontal position  



void setup(){
  size(400, 300);
  //list all the available serial ports
  println(Serial.list());

  myPort = new Serial(this, Serial.list()[7], 9600);

  //reads bytes into a buffer until you get a newline (ASCII 10);
  myPort.bufferUntil('\n');

  //set initial background and smooth drawing:
  background(#543174);
  smooth();
  //for a list of cameras on your computer, use this line:
  println(Capture.list());

  //use the default camera for capture at 30 fps
  myCam = new Capture(this, width, height, 30);
  myCam.start();
}

void draw(){
  //make a single number fmor the current hour, minute, and second
  currentTime = hour() * 3600 + minute() * 60 + second();

  if (myCam.available() == true) {
    //draw the camera image to the screen;
    myCam.read();
    set(0, 0, myCam);

    //get the time as a string
    String timeStamp = nf(hour(), 2) + ":" + nf(minute(), 2)
    + ":" + nf(second(), 2) + "   " + nf(day(), 2) + "-"
    + nf(month(), 2) + "-" + nf(year(), 4);

    //draw a dropshadow for the time text:
    fill(15);
    text(timeStamp, 11, height - 19);
    //draw the main time next
    fill(255);
    text(timeStamp, 10, height - 20);
  }
}

void serialEvent (Serial myPort){
  //get the ASCII string
  String inString = myPort.readStringUntil('\n');

  if (inString != null){
    //trim off any whitespace:
    inString = trim(inString);
    //convert to an int and map to the screen height
    sensorValue = float(inString);
    //println(sensorValue);
    sensorValue = map(sensorValue, 0, 1023, 0, height);
    println(sensorValue);

    if (sensorValue &gt; threshold){
      if(currentTime - lastPictureTime &gt; pictureInterval){
        PImage thisFrame = get();
        thisFrame.save(fileName);
        postPicture();
        lastPictureTime = currentTime;
      }
      //if the last reading was less than the threshold
      //then the cat just got on the mat
      if(prevSensorValue &lt;= threshold){
        println("Peti na casinha");
        sendMail();
      }
    }
    else{
      //if the sensor value is less than the threshold,
      //and the previous value was greater, then the cat
      //just left the mat
      if (prevSensorValue &gt; threshold){
        println("Peti não está na casinha");
      }
    }
    //save the current value for the next time
    prevSensorValue = sensorValue;
  }
}


void sendMail(){
  //how long has passed since the last mail
  int timeDifference = currentTime - lastMailTime;

  if( timeDifference &gt; mailInterval){
    String[] mailScript = loadStrings(mailUrl);
    println("results from mail script:");
    println(mailScript);

    //save the current minute for next time
    lastMailTime = currentTime;
  }
}

void postPicture(){
  //load the saved image into an array of bytes
  byte[] thisFile=loadBytes(fileName);

  //open a new connection to the server
  thisClient = new Client(this, "localhost", 80);
  //make an HTTP POST request:
  thisClient.write("POST" + pictureScriptUrl + " HTTP/1.1\n");
  thisClient.write("Host: localhost\n");
  //tell the server you're sending the POST in multiple parts
  //and send a unique string that will delineate the parts
  thisClient.write("Content-Type: multipart/form-data; boundary=");
  thisClient.write(boundary + "\n");

  //form the beginning of the request
  String requestHead ="\n--" + boundary + "\n";
  requestHead +="Content-Disposition: form-data; name=\"file\"; ";
  requestHead += "filename=\"" + fileName + "\"\n";
  requestHead +="Content-Type: image/jpeg\n\n";

  //form the end of the request
  String tail="\n\n--" + boundary + "--\n\n";

  //calculate and send the length of the total request
  //including the head of the request, the file, and the tail
  int contentLength = requestHead.length() + thisFile.length + tail.length();
  thisClient.write("Content-Length: " + contentLength + "\n\n");

  //send the header of the request, the file and the tail
  thisClient.write(requestHead);
  thisClient.write(thisFile);
  thisClient.write(tail);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>integrate a "choose ip to connect to" in a processing android sketch.</title>
      <link>https://forum.processing.org/two/discussion/9451/integrate-a-choose-ip-to-connect-to-in-a-processing-android-sketch</link>
      <pubDate>Mon, 16 Feb 2015 14:35:11 +0000</pubDate>
      <dc:creator>donuan</dc:creator>
      <guid isPermaLink="false">9451@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I have question concerning setting the remote location in a processing android sketch.</p>

<p>I am using a processing android sketch running on a nexus 7 in a visual installation to control a processing sketch on a mac computer running yesemite via OSC.
This works well as long as the specified remote location in the android sketch has the correct ip that the computer is using.</p>

<p>My problem is that this ip is changing every time the computer connects to the network, and the network (which is a university network) does not allow for connecting with a static ip. I could change the ip in the android sketch and upload it again to the tablet but as this is an installation that will be standing for a month this would be a lot of hassle.
I am therefor wondering if there is a way to integrate a setting in the android sketch where you from the android tablet could choose the ip to send to without having to reinstall the sketch on the android tablet?</p>

<p>alternatively, how can you set up a local network for the mac and the nexus to communicate on? 
I have been unable to do that as the nexus does not recognise the macs local network.</p>

<p>3rd option would be to connect them via bluetooth but I do not know how to/ if you can send OSC messages via bluetooth.</p>

<p>wouold be very thankful for any help as the exhibition starts in 2 weeks and I dont know how to solve this.
Thank you!</p>
]]></description>
   </item>
   </channel>
</rss>